package object2;

import java.lang.Override;

/**
 * 面向对象编程（中级部分）练习
 */
public class Object2Exercise01 {

    public static void main(String[] args) {
        /*
            定义一个man类{name, age, job}，初始化Person对象数组，有3个Person对象，并按age从大到小进行排序
         */
        Man man1 = new Man("张三", 27, "程序员");
        Man man2 = new Man("李四", 26, "程序员");
        Man man3 = new Man("王五", 28, "程序员");
        Man[] men = new Man[3];
        men[0] = man1;
        men[1] = man2;
        men[2] = man3;
        for (int i = 0; i < men.length; i++) {
            for (int j = 0; j < men.length - 1 - i; j++) {
                if (men[j].age > men[j + 1].age) {
                    Man temp = new Man(men[j + 1].name, men[j + 1].age, men[j + 1].job);
                    men[j + 1] = men[j];
                    men[j] = temp;
                }
            }
        }
        System.out.println("=======冒泡排序后结果=======");
        for (int i = 0; i < men.length; i++) {
            System.out.println(men[i]);
        }

    }
}

class Man {

    public String name;

    public int age;

    public String job;

    public Man(String name, int age, String job) {
        this.name = name;
        this.age = age;
        this.job = job;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getJob() {
        return job;
    }

    public void setJob(String job) {
        this.job = job;
    }

    @Override
    public String toString() {
        return "Man{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", job='" + job + '\'' +
                '}';
    }
}
